<template>
	<sw-common-frame :count="dataCount" :loading="loading">
		<el-button slot="button" size="small" type="primary" icon="el-icon-plus" @click="handleOpenDialog()">新增</el-button>
		<el-form slot="query" size="small" inline>
			<el-form-item>
				<el-input v-model="queryData.name" clearable placeholder="栏目名称" style="width: 180px"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="queryTableData()">查询</el-button>
			</el-form-item>
		</el-form>
		<el-table slot="table" size="medium" :data="tableData" stripe height="100%">
			<el-table-column label="序号" type="index" align="center" width="50" />
			<el-table-column label="配置名称" prop="label" min-width="240"></el-table-column>
			<el-table-column label="配置字段" prop="code" min-width="240"></el-table-column>
			<el-table-column label="适用类型" width="150" :formatter="returnApplyTypeName" />
			<el-table-column label="配置类型" width="120" :formatter="returnConfigTypeName" />
			<el-table-column label="创建时间" prop="createTime" width="160"></el-table-column>
			<el-table-column label="操作" width="132">
				<el-button-group slot-scope="{ row }">
					<el-button size="mini" type="warning" @click="handleOpenDialog(row)">修改</el-button>
					<el-button size="mini" type="danger" @click="handleDeleteData(row)">删除</el-button>
				</el-button-group>
			</el-table-column>
		</el-table>
		<sw-pagination slot="page" :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()" />
		<form-dialog v-model="formDialog" :data="configData" @refresh="queryTableData()"></form-dialog>
	</sw-common-frame>
</template>

<script>
import formDialog from './form';
import listMixins from '@/mixins/listMixins';
import { applyType, configType } from '@/utils/constants';
import { getBaseInfoList, deleteBaseInfo } from '@/api/system/sysBaseInfo';
export default {
	mixins: [listMixins],
	components: { formDialog },
	data() {
		return {
			pageName: '网站配置',
			configData: {}
		};
	},
	computed: {
		listFunction() {
			return eval(getBaseInfoList);
		},
		deleteFunction() {
			return eval(deleteTopicLibrary);
		}
	},
	methods: {
		//返回适用类型名称
		returnApplyTypeName(data) {
			let info = applyType.find((n) => n.type == data.scopeType);
			return info?.label || '';
		},
		//返回配置类型名称
		returnConfigTypeName(data) {
			let info = configType.find((n) => n.type == data.type);
			return info?.label || '';
		},
		handleOpenDialog(data) {
			this.formDialog = true;
			this.configData = !data ? {} : { ...data };
		}
	}
};
</script>
